<?php
//聊天记录处理主函数
function DealMsg($filename,$typedir,$date,$type)
{
	$var_date = $date;
	if(!file_exists(DOC_ROOT.''.$typedir.''.$filename))
	{
		echo 'no file';
		die();
	}

	
	$file = file(DOC_ROOT.''.$typedir.''.$filename);
	
	$count = count($file);
	$spam = "10000";
	$dateReg = "/\d{4}\-\d{2}\-\d{2} \d{1,2}\:\d{1,2}\:\d{1,2}/";
	$qqReg = "/\(\d.+\)/";
	
	$render = "";
	
	for($i=0; $i <$count; $i++){
		$line = $file[$i]; 
		if(strpos($line,$var_date)==false)
		{
			//break;
		}
		if(stristr($line,$date))
		{
			$line = preg_replace($dateReg, "", $line);
			$line = preg_replace($qqReg, "", $line);
			$line = str_replace(PHP_EOL, '', $line); 
			$line = str_replace(' ', '', $line); 
			
			$author = $line;
		

			/*
			if(IsMarkGod($author))
			{
				$line = "<span class=\"ring1\">".$author."</span>";					
			}
			*/
			$line ="<B>".$line."说：</B><br />"; 
			$render = $render.$line;
			$i = $i + 1; 
			
			while($i <= $count){
				$line = $file[$i];
				//判断是否为日期类型，如果是则跳出while循环，否则继续
				if (preg_match($dateReg, $line)){
					$i = $i - 1; 
					break;
				}
				$i = $i + 1; 
				//如果字符串为空行，则跳至下一行处理
				if(strlen($line)<=1)
				{
					continue;
				}
				//正文内容空两格
				$line="　　".$line;
				//教主的话特别标识
				if(IsMarkGod($author))
				{
					$line = "<span class=\"ring1\">".$line."</span>";					
				}
				$render = $render.$line.'<br />';
			}
		
		}
	}
	$render = '<h1>'. $date . '聊天记录</h1>' . $render;
	return $render;
	/*
	echo '<h1>';
	echo $_POST['date'];
	echo '聊天记录</h1>';
	echo $render;
	*/
}

function IsMarkGod($author)
{
	//echo $author;
	$godlist = "易仁永澄<iyongcheng@qq.com>"; 
	if(stristr($godlist,$author))
	{
		return true;			
	}
	return false; 
}